package com.ukao.steward.adapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.ProductListBean;
import com.ukao.steward.util.CheckUtils;

import java.util.List;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class StorageClothingListAdapter extends ListBaseAdapter<ProductListBean> {




    public StorageClothingListAdapter(Context mContext, List<ProductListBean> datas) {
        super(mContext, datas);

    }


    @Override
    public int getLayoutId() {
        return R.layout.adapter_storage_clothing_list;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        TextView price = holder.getView(R.id.price);
        TextView totalPrice = holder.getView(R.id.total_price);
        TextView cnt = holder.getView(R.id.cnt);
        TextView name = holder.getView(R.id.product_name);
        TextView discount= holder.getView(R.id.discount);
        Button mbingBtn= holder.getView(R.id.bing_btn);
        TextView bindCode = holder.getView(R.id.bindCode);

        ProductListBean item = mDataList.get(position);
        name.setText(CheckUtils.isEmptyString(item.getProductName()));/*衣物*/
        cnt.setText( "x" + (item.getCount()/100));/* 与数量*/
        price.setText("￥" + CheckUtils.isEmptyNumber(item.getServiceAmt()));/*单价*/
        String  discounts=CheckUtils.isDiscount(item.getDiscount());
        if (!CheckUtils.isEmpty(item.getBindCode())){
            mbingBtn.setBackgroundResource(R.drawable.green_bt_selector);
        }else{
            mbingBtn.setBackgroundResource(R.drawable.blue_bt_selector);
        }
        mbingBtn.setVisibility(item.isEnableBindCode()?View.VISIBLE:View.GONE);
        bindCode.setText(CheckUtils.isEmptyString(item.getBindCode()));

        if (CheckUtils.isEmpty(item.getBindCode())){
            mbingBtn.setText(R.string.tie_the);
        }else{
            mbingBtn.setText(R.string.has_been_tied);
        }

        if (CheckUtils.isEmpty(discounts)){
            discount.setText("");
        }else{
            discount.setText("*"+discounts+"折");

        }
        totalPrice.setText("￥"+CheckUtils.isEmptyNumber(item.getSubtotal()));

        mbingBtn.setOnClickListener(v -> {
            if (mOnItemChildClickListener!=null)
                mOnItemChildClickListener.onChildItemClick(R.id.bing_btn,position,getItem(position));
        });
    }
}
